package org.ns.longhttp.handler.asynchandler;

import java.util.concurrent.ConcurrentHashMap;

public abstract class AbstractUrlEventQueue implements UrlEventQueue {

    private ConcurrentHashMap<String, Boolean> urlQueueDuplicate = new ConcurrentHashMap<>();

    @Override
    public void add(String url) {
        if (urlQueueDuplicate.putIfAbsent(url, true) == null) {
            put(url); // 子类实现吧
        }
    }

    protected abstract void put(String url) ;

    @Override
    public void consume(String url) {
        urlQueueDuplicate.remove(url);
    }
}
